package com.mmy.controller.signup;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import com.mmy.controller.FileUtils;
import com.mmy.domain.sys.TSysOrg;
import com.mmy.domain.sys.TSysUser;
import com.mmy.service.impl.sys.SysOrgServiceImpl;
import com.mmy.service.impl.sys.SysUserServiceImpl;

import lombok.extern.slf4j.Slf4j;

/**
 * @vesion
 * @description 旅行社和营业部注册
 * @author liys
 * @date 2021-6-4
 */

@Controller
@Slf4j
public class SignUpController {

	@Value("${web.upload-path}")
	private String userPath;

	@Autowired
	SysOrgServiceImpl orgService;
	@Autowired
	SysUserServiceImpl userService;

	@RequestMapping("/tourwelcome")
	public String welcome() {

		return "signup/tour";
	}

	
	 @RequestMapping("/tourwelcome2") 
	 public String welcome2() {
	  
		 return "signup/tour2"; 
	 }
	 
	/**
	 * @descr 总社注册--提交
	 * @param
	 * @return
	 * @throws @author liys
	 * @date 2021-6-7
	 */
	@RequestMapping("/uploadtest")
	@ResponseBody
	public String uploadTest(MultipartHttpServletRequest request) {

		// 新建旅行社
		TSysOrg org = new TSysOrg();
		org.setOrgName(request.getParameter("cOrgName"));
		org.setContact(request.getParameter("cContant"));
		org.setMobile(request.getParameter("cMobile"));
		org.setFax(request.getParameter("cFax"));
		org.setTel(request.getParameter("cTel"));
		String iZoneID = request.getParameter("iZoneID");
		org.setZoneID(Integer.parseInt(iZoneID.split(",")[2]));
		org.setAddress(request.getParameter("cAddress"));
		org.setMemo(request.getParameter("cMemo"));
		MultipartFile file1 = request.getFile("file1");
		MultipartFile file2 = request.getFile("file2");
		String path = userPath;
		// 营业执照
		String local = FileUtils.upload(file1, path);
		org.setSpare1(local);
		// 身份证
		String local2 = FileUtils.upload(file2, path);
		org.setSpare2(local2);
		// 赋予待审核状态
		org.setSpare5("0");
		int iOrgID = orgService.createSysOrgSelf(org);

		// 同时创建个经理账号
		TSysUser tSysUser = new TSysUser();
		tSysUser.setUserName(org.getContact());
		tSysUser.setUserAccount(org.getMobile());
		tSysUser.setOrgID(iOrgID);
		tSysUser.setUserType((byte) 1);
		tSysUser.setUserMobile(org.getMobile());
		// 设置未审核状态,该状态不能登录
		tSysUser.setSpare1("0");
		userService.createStaffSelf(tSysUser);
		return "我是返回值";
	}

	/**
	 * @descr 分社注册--提交
	 * @param
	 * @return
	 * @throws @author liys
	 * @date 2021-6-7
	 */
	@RequestMapping("/uploadtest2")
	@ResponseBody
	public String uploadTest2(MultipartHttpServletRequest request) {

		// 新建旅行社
		TSysOrg org = new TSysOrg();
		org.setOrgName(request.getParameter("cOrgName"));
		org.setContact(request.getParameter("cContant"));
		org.setMobile(request.getParameter("cMobile"));
		org.setFax(request.getParameter("cFax"));
		org.setTel(request.getParameter("cTel"));
		String iZoneID = request.getParameter("iZoneID");
		org.setZoneID(Integer.parseInt(iZoneID.split(",")[2]));
		org.setAddress(request.getParameter("cAddress"));
		org.setMemo(request.getParameter("cMemo"));
		MultipartFile file1 = request.getFile("file1");
		MultipartFile file2 = request.getFile("file2");
		MultipartFile file3 = request.getFile("file3");
		MultipartFile file4 = request.getFile("file4");
		String path = userPath;
		// 营业执照
		String local = FileUtils.upload(file1, path);
		org.setSpare1(local);
		// 身份证
		String local2 = FileUtils.upload(file2, path);
		org.setSpare2(local2);
		// 总社营业执照
		String local3 = FileUtils.upload(file3, path);
		org.setSpare3(local3);
		// 身份证
		String local4 = FileUtils.upload(file4, path);
		org.setSpare4(local4);
		// 赋予待审核状态
		org.setSpare5("0");
		int iOrgID = orgService.createSysOrgSelf(org);

		// 同时创建个经理账号
		TSysUser tSysUser = new TSysUser();
		tSysUser.setUserName(org.getContact());
		tSysUser.setUserAccount(org.getMobile());
		tSysUser.setOrgID(iOrgID);
		tSysUser.setUserType((byte) 1);
		tSysUser.setUserMobile(org.getMobile());
		// 设置未审核状态,该状态不能登录
		tSysUser.setSpare1("0");
		userService.createStaffSelf(tSysUser);
		return "我是返回值";
	}
}
